#include <iostream>
#include <objbase.h>
#include <initguid.h>

#include "IFastString.h"

using namespace std;

int main()
{
    cout << "hello, world" << endl;

	// Initialize COM Library
	CoInitialize(nullptr);

	IFastString* pIFastString = nullptr;
	HRESULT hr = ::CoCreateInstance(CLSID_FastString,
		nullptr,
		CLSCTX_INPROC_SERVER,
		IID_IFastString,
		(void**)&pIFastString);

	if (SUCCEEDED(hr)) {
		pIFastString->SetContent("abc");

		cout << "len: " << pIFastString->Length() << endl;

		IPersistentObject* pIPersistentObject = nullptr;
		hr = pIFastString->QueryInterface(IID_IPersistentObject, (void**)&pIPersistentObject);
		if (SUCCEEDED(hr)) {
			pIPersistentObject->Save("file.txt");
			pIPersistentObject->Release();
			pIPersistentObject = nullptr;
		}

		pIFastString->Release();
		pIFastString = nullptr;
	}
	else
	{
		cout << "Client: \t\tCould not create component. hr = "
			<< hex << hr << endl;
	}

	// Uninitialize COM Library
	CoUninitialize();

    return 0;
}
